package com.cn.wanxi.servlet.designer;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.DesignerModel;
import com.cn.wanxi.model.ResultModel;
import com.cn.wanxi.model.UserModel;
import com.cn.wanxi.service.DesignerService;
import com.cn.wanxi.service.UserService;
import com.cn.wanxi.service.impl.DesignerServiceImpl;
import com.cn.wanxi.service.impl.UserServiceImpl;
import com.cn.wanxi.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/designer/getCount")
public class DesignerGetCountServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //      0.乱码解决
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //1.得到前端传递过来的数据
        String designer_name = req.getParameter("designer_name");
        String phone = req.getParameter("phone");
        String sex = req.getParameter("sex");
        String enable = req.getParameter("enable");
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String pageNo = req.getParameter("pageNo");
        String pageSize = req.getParameter("pageSize");

        //        2.将数据封装到对象
        DesignerModel designerModel = new DesignerModel();

        designerModel.setPageNo(Tool.stringToPageNum(pageNo));
        designerModel.setPageSize(Tool.stringToPageSize(pageSize));
        designerModel.setDesignername(Tool.nullToString(designer_name));
        designerModel.setPhone(Tool.nullToString(phone));
        designerModel.setSex(Tool.nullToString(sex));
        designerModel.setEnable(Tool.stringToInt(enable));
        designerModel.setStart(Tool.nullToString(start));
        designerModel.setEnd(Tool.nullToString(end));

        DesignerService designerService = new DesignerServiceImpl();

        ResultModel resultModel = designerService.getCount(designerModel);
        resp.getWriter().print(JSONObject.toJSONString(resultModel));
    }
}
